﻿using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace Omu.Awesome.Mvc.Helpers
{
    public static class AjaxRadioListHelpers
    {
        public static MvcHtmlString AjaxRadioList(this HtmlHelper html, AjaxRadioListParams o)
        {
            o.ReadMeta(html);

            o.Value = o.Value.FromModel(html, o.Prop);

            var hd = o.HtmlAttributes.GetDictionary();
            var h = !html.ViewData.ModelState.IsValidField(o.Prop)
                        ? hd.AddVal("class", "input-validation-error")
                        : hd;

            o.Controller = o.Controller.DefaultController(o.Prop, "AjaxRadioList");
            var info = new AjaxRadioListInfo { HtmlAttributes = h.ToHtml() };
            info.ReadParams(o);

            return html.Partial(Settings.AwesomeFolder + "AjaxRadioList.ascx", info);
        }

        public static MvcHtmlString AjaxRadioList(this HtmlHelper html,
                                                  string prop,
                                                  object value = null,
                                                  string controller = null,
                                                  object htmlAttributes = null,
                                                  string prefix = null,
                                                  string parentId = null,
                                                  string area = null)
        {
            return
                html.AjaxRadioList(new AjaxRadioListParams
                                       {
                                           Controller = controller,
                                           HtmlAttributes = htmlAttributes,
                                           ParentId = parentId,
                                           Prefix = prefix,
                                           Prop = prop,
                                           Value = value,
                                           Area = area
                                       });
        }
    }
}